<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2007 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 *
 * Link dialog window.
-->
<html>
<head>
	<title>Formula Editor</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="robots" content="noindex, nofollow" />
	<script type="text/javascript">

var oEditor		= window.parent.InnerDialogLoaded() ;
var FCK			= oEditor.FCK ;
var FCKLang		= oEditor.FCKLang ;
var FCKConfig	= oEditor.FCKConfig ;
var FCKRegexLib	= oEditor.FCKRegexLib ;
var FCKTools	= oEditor.FCKTools ;

document.write( '<script src="' + FCKConfig.BasePath + 'dialog/common/fck_dialog_common.js" type="text/javascript"><\/script>' ) ;

	</script>
	<script type="text/javascript">

// Get the selected flash embed (if available).
var oMathImage = FCK.Selection.GetSelectedElement() ;

if ( oMathImage )
{
	if ( oMathImage.tagName != 'IMG' || !oMathImage.getAttribute('_fck_mw_math') )
		oMathImage = null ;
}

window.onload = function()
{
	// Translate the dialog box texts.
	oEditor.FCKLanguageManager.TranslatePage(document) ;

	// Load the selected link information (if any).
	LoadSelection() ;

	// Activate the "OK" button.
	window.parent.SetOkButton( true ) ;
	window.parent.SetAutoSize( true ) ;
	GetE('xTemplateRaw').focus();
}

function LoadSelection()
{
	if ( !oMathImage ) return ;

	GetE('xTemplateRaw').value = oMathImage.getAttribute( '_fck_mw_math' ) ;
}

//#### The OK button was hit.
function Ok()
{
	var formula = GetE('xTemplateRaw').value.Trim() ;

	if ( formula.length == 0 )
	{
		alert( FCKLang.wikiTeXEmpty || 'Please type the formula' ) ;
		return false ;
	}

	if ( oEditor.window.parent.FCKeditorAPI && oEditor.window.parent.FCKeditorAPI.Version.match( /^2\.5/ ) ) {
		window.parent.document.getElementById( 'btnOk' ).disabled = true ;
		window.parent.document.getElementById( 'btnCancel' ).disabled = true ;
	}

	oEditor.window.parent.sajax_request_type = 'GET' ;
	oEditor.window.parent.sajax_do_call( 'wfSajaxGetMathUrl', [formula], UpdateImageFromAjax ) ;

	return false ;
}

function UpdateImageFromAjax( response )
{
	oEditor.FCKUndo.SaveUndoStep() ;

	if ( !oMathImage )
	{
		oMathImage = FCK.CreateElement( 'IMG' ) ;
		oMathImage.className = 'FCK__MWMath' ;
		oMathImage.src = FCKConfig.PluginsPath + 'mediawiki/images/icon_math.gif' ;
	}
	else
	{
		if ( response.responseText )
		{
			oMathImage.src = response.responseText ;
			SetAttribute( oMathImage, "_fcksavedurl", response.responseText ) ;
		}
		else
		{
			oMathImage.src = FCKConfig.PluginsPath + 'mediawiki/images/icon_math.gif' ;
		}
	}

	SetAttribute( oMathImage, "_fck_mw_math", GetE('xTemplateRaw').value.Trim() ) ;
	SetAttribute( oMathImage, "_fckfakelement", 'true' ) ;

	// Call it using setTimeout to avoid a strange behavior in Firefox.
	window.setTimeout( window.parent.Cancel, 0 ) ;
}

	</script>
</head>
<body style="overflow: hidden">
	<div id="divInfo">
		<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
			<tr>
				<td>
					<span fcklang="wikiTeX">Formula (TeX markup)</span>
				</td>
			</tr>
			<tr>
				<td height="100%">
					<textarea id="xTemplateRaw" style="width: 100%; height: 100%; font-family: Monospace"
						cols="50" rows="10" wrap="off"></textarea>
				</td>
			</tr>
		</table>
	</div>
</body>
</html>
